import 'package:flutter/material.dart';
import 'package:get/get.dart';

// locale's Map<String, String>
import 'lang_en_us.dart';
import 'lang_zh_hans.dart';
import 'lang_zh_hk.dart';
import 'lang_pt_br.dart';

/* 一旦GetX切换语言，重新打开App不会重置为默认语言 */
class TranslationService extends Translations {
  /*
   * Get.deviceLocale 当前设备默认语言类型
   * Get.locale GetX当前使用的语言类型
   */
  static Locale get locale => Get.deviceLocale;
  static final fallbackLocale = Locale('zh', 'Hans');

  /// 构造函数初始化的时候GetX还没有设置语言
  // TranslationService() {
  //   print(Get.deviceLocale);// zh_Hans_CN
  //   print(Get.locale);// null
  // }

  /*
   * set setKey(String key) {}
   * 
   * getter 通过属性访问；定义时 `花括号 return value`.
   * Map<String, Map<String, String>> get keys => {'xxx': 'xxx'};
   */
  @override
  Map<String, Map<String, String>> get keys {
    return {
      'en_US': en_US,
      'zh_Hans': zh_Hans,
      'zh_HK': zh_HK,
      'pt_BR': pt_BR,
    };
  }
}

/*
https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html

https://www.ibabbleon.com/iOS-Language-Codes-ISO-639.html
*/
